namespace OpenXmlWriter.Packaging
{
  public class ContentType
  {
    private string _extensionOrPartName;
    private string _type;
    private bool _isDefault;

    public ContentType(string extension, string type) : this(extension, type, true)
    {
    }

    public ContentType(string extesionOrPartName, string type, bool isDefault)
    {
      _extensionOrPartName = extesionOrPartName;
      _type = type;
      _isDefault = isDefault;
    }

    public string Xml
    {
      get
      {
        string result;
        if (_isDefault)
        {
          result = string.Format("<Default Extension=\"{0}\" ContentType=\"{1}\" />", _extensionOrPartName, _type);
        }
        else
        {
          result = string.Format("<Override PartName=\"{0}\" ContentType=\"{1}\" />", "/" + _extensionOrPartName, _type);
        }
        return result;
      }
    }
  }
}